iOS 9系统下 “人民币的特殊性”
NSString * string = @"9999";
NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
moneyFormatter.numberStyle = kCFNumberFormatterCurrencyStyle;
NSString *priceString = [moneyFormatter stringFromNumber:[NSNumber numberWithDouble:[string doubleValue]]];
NSMutableString *priceMstr = [NSMutableString stringWithFormat:@"%@",priceString];
NSLog(@"%@",priceMstr);
其输出结果为 “¥ 9,999.00” ,而不是我们预期的 “¥9,999.00”。
¥ 与 "9,999.00" 之间的空白地带,是无法用替换空格的方式直接消除的的。
即使用如下方法将不起作用
NSRange range = [priceMstr rangeOfString:@" "];
if (range.location != NSNotFound) {
[priceMstr replaceCharactersInRange:range withString:@""];
}
看来它是一个特殊的字符那么我们不得不采用其他的办法来处理。
添加如下代码即可处理掉人民币货币符号 与 价格之间的空格:
[priceMstr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];